<?php

namespace App\Console\Commands;

use App\Models\StoreGoods;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;

class Groupbooking extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:Groupbooking';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        //获取所有拼团数据
        $list = StoreGoods::GroupBookingShow();
        if (empty($list)) return Log::info('拼团数据更新失败，当前时间是：' . date() . '请尽快查看');
        //通过循环添加拼团数据进入缓存
        foreach ($list as $value) {
            $result = Redis::hset('GroupbookingShow', $value['id'], json_encode($value, true));
            if (!$result){
                Log::info('缓存更新中第'.$value['id'].'添加时出现错误，时间是：'.date());
            }
        }
        Log::info('缓存更新成功，时间是：'.date());
    }
}
